const INFO_KEY = 'shop_user_info'
const HISTORY_KEY = 'history'
// 获取个人凭证
export const getUserInfo = () => {
  const userInfo = localStorage.getItem(INFO_KEY)
  return userInfo ? JSON.parse(userInfo) : { token: null, userId: null } // 返回一个空对象
}
// 设置个人凭证
export const setUserInfo = (userInfo) => {
  localStorage.setItem(INFO_KEY, JSON.stringify(userInfo))
}
// 移除个人凭证
export const removeUserInfo = () => {
  localStorage.removeItem(INFO_KEY)
}
/* ----------------------------------------------------------------------------------------
   ---------------------------------------------------------------------------------------- */
// 获取搜索历史
export const getHistory = () => {
  const history = localStorage.getItem(HISTORY_KEY)
  return history ? JSON.parse(history) : [] // 返回一个空数组
}

// 设置搜索历史
export const setHistory = (history) => {
  localStorage.setItem(HISTORY_KEY, JSON.stringify(history))
  return history
}

// 移除搜索历史 可能没用但就要写
export const removeHistory = () => {
  localStorage.removeItem(HISTORY_KEY)
}
